//
//  SettingTitleViewController.m
//  XinKaiFa55like
//
//  Created by 55like on 2017/9/22.
//  Copyright © 2017年 55like lj. All rights reserved.
//

#import "SettingTitleViewController.h"

@interface SettingTitleViewController ()<UITextFieldDelegate>

@property (nonatomic,copy)void(^block)();


@end

@implementation SettingTitleViewController
{
    
    UITextField * textfiel;
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = rgb(242, 242, 242);
    self.block = self.userInfo[@"block"];
    
    self.navrightButton = [self rightButton:@"完成" image:nil sel:@selector(save)];
    [self.navrightButton setTitleColor:rgbpublicColor forState:UIControlStateNormal];
    self.navleftButton = [self leftButton:@"取消" image:nil sel:@selector(backButtonClicked:)];
    [self.navleftButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    
    
    
    UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, 64+10, kScreenWidth, 44)];
    view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:view];
    
    textfiel = [RHMethods textFieldlWithFrame:CGRectMake(10, 0, kScreenWidth - 20, view.frameHeight) font:Font(14) color:[UIColor blackColor] placeholder:@"请输入" text:[self.userInfo valueForJSONStrKey:@"text"]];
    textfiel.delegate = self;
    [textfiel becomeFirstResponder];
    [view addSubview:textfiel];
    
    
}
-(void)save{
    
    NSString * str = [self.userInfo valueForJSONStrKey:@"title"];
    NSString * key = @"";
    NSString * msg = @"请输入";
    if ([str isEqualToString:@"邮箱"]) {
        
        key = @"email";
        msg = @"请输入邮箱";
        
    }else if ([str isEqualToString:@"名字"]){
        
        key = @"realname";
        msg = @"请输入名字";
        
    }else if ([str isEqualToString:@"电话"]){
        
        
        key = @"tel";
        msg = @"请输入手机号";
        
    }else if ([str isEqualToString:@"微信"]){
        
        
        key = @"wechat";
        msg = @"请输入微信号";
        
    }
    if (textfiel.text.length == 0) {
        
        [SVProgressHUD showImage:nil status:msg];
        
        return;
    }
    krequestParam
    
    [dictparam setValue:textfiel.text forKey:key];
    [NetEngine createHttpAction:@"user/profiles" withCache:NO withParams:dictparam withMask:SVProgressHUDMaskTypeNil onCompletion:^(id resData, BOOL isCache) {
        [SVProgressHUD showImage:nil status:[resData valueForJSONStrKey:@"info"]];
        if ([[resData valueForJSONStrKey:@"status"] isEqualToString:@"200"]) {
            

            if (self.block) {
                
                self.block();
            }
            [self backButtonClicked:nil];
            
        }else{
            
            
            
            
            
            
        }
        
    } onError:^(NSError *error) {
        
    }];
    
    
    
    
    
}
#pragma mark -  textfield代理方法

//return键触发方法
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    
    [self.view endEditing:YES];
    
    return YES;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
